package com.ruoyi.web.controller.background;


import com.ruoyi.background.domain.AppBanner;
import com.ruoyi.background.service.IAppBannerService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小程序bannerController
 *
 * @author susu
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/banner/banner")
public class AppBannerController extends BaseController {
    @Autowired
    private IAppBannerService appBannerService;

    /**
     * 查询小程序banner列表
     */
    @PreAuthorize("@ss.hasPermi('banner:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppBanner appBanner) {
        startPage();
        List<AppBanner> list = appBannerService.selectAppBannerList(appBanner);
        return getDataTable(list);
    }

    /**
     * 导出小程序banner列表
     */
    @PreAuthorize("@ss.hasPermi('banner:banner:export')")
    @Log(title = "小程序banner" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppBanner appBanner) {
        List<AppBanner> list = appBannerService.selectAppBannerList(appBanner);
        ExcelUtil<AppBanner> util = new ExcelUtil<AppBanner>(AppBanner.class);
        util.exportExcel(response, list, "小程序banner数据");
    }

    /**
     * 获取小程序banner详细信息
     */
    @PreAuthorize("@ss.hasPermi('banner:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appBannerService.selectAppBannerById(id));
    }

    /**
     * 新增小程序banner
     */
    @PreAuthorize("@ss.hasPermi('banner:banner:add')")
    @Log(title = "小程序banner" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppBanner appBanner) {
        return toAjax(appBannerService.insertAppBanner(appBanner));
    }

    /**
     * 修改小程序banner
     */
    @PreAuthorize("@ss.hasPermi('banner:banner:edit')")
    @Log(title = "小程序banner" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppBanner appBanner) {
        return toAjax(appBannerService.updateAppBanner(appBanner));
    }

    /**
     * 删除小程序banner
     */
    @PreAuthorize("@ss.hasPermi('banner:banner:remove')")
    @Log(title = "小程序banner" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appBannerService.deleteAppBannerByIds(ids));
    }
}
